#lang rosetta-racket


(provide scriptecture-tessellation-aab
         scriptecture-tessellation-nob
         scriptecture-tessellation-cylinders
         scriptecture-tessellation-cross-cylinders)


(define scriptecture-skin
  (make-simple-skin
   (λ (u v)
     (xyz u v (+ (* 0.5 (sin (+ (* 0.75 u)))) (* 1.5 (sin (* 0.5 v))))))
   (make-uv-domain 'closed -5 'closed 5
                   'closed -5 'closed 5)))


(define (scriptecture-tessellation-aab n-u n-v s)
  (map
   (λ (patch)
     (move
      (patch-object patch)
      (box s s s)))
   (cut scriptecture-skin (list n-u n-v))))

(define (scriptecture-tessellation-nob n-u n-v s)
  (map
   (λ (patch)
     (move
      (patch-object patch)
      (box-n s s (random) (patch-normal patch) 'bottom)))
   (cut scriptecture-skin (list n-u n-v))))

(define (scriptecture-tessellation-cylinders n-u n-v r f h)
  (map
   (λ (patch)
     (let ((p (patch-object patch)))
       (cylinder (z p 0) r (+z p h))))
   (cut (make-sinwave-skin f f f) (list n-u n-v))))

(define (scriptecture-tessellation-cross-cylinders n-u n-v r f1 f2)
  (map
   (λ (bot-patch top-patch)
     (let ((p1 (patch-object bot-patch))
           (p2 (patch-object top-patch)))
       (cylinder
        p1
        r
        (+z p2 4))))
   (cut (make-sinwave-skin f1 f1 f1) (list n-u n-v))
   (cut (make-sinwave-skin f2 f2 f2) (list n-u n-v))))